#! /usr/bin/perl -w
use strict;

print "Input filename: ";
my $ofn = <STDIN>;
print "filename: $ofn \n";
chomp $ofn;
open OFD, ">>".$ofn || die "cannot open target file";
my $prefix;
print "Input prefix: ";
$prefix = <STDIN>;
print "prefix: $prefix \n";
chomp $prefix;
my $defname;
my $val;
my $input;
while(1){
	print "#define:  ";
	$input = <STDIN>;
	chomp $input;
	last if($input =~ m/^exit$/i);

	if($input =~ m/^ack$/i){
		$defname .= 'Ack';
		$val     += 1;
	}
	elsif($input =~ m/^set$/i){
		$defname =~ s/^Req/Set/i;
		$val -= 1 if(($defname =~ s/ack//i) > 0);
	}
	else{
		$defname = $input;
		$val = <STDIN>;
		chomp $val;
	}
	print "#define $defname $val\n";
	printf OFD '#define   %-35s  %-10s'."\n", $prefix.$defname, $val; 
}
close OFD;
